<template>
  <div class="like">
    <NavBar title="我的收藏" left-arrow @click-left="onClickLeft" />
    <div class="jing">
      <div class="jing_for" v-for="(item,index) in list" :key="index">
        <p>{{item.title}}</p>
        <p class="p_small">
          共1课时
          <span>
            <Icon class="icon" @click="delLike" color="orange" name="star" />
          </span>
        </p>
        <p class="p_main">
          <img class="jing_img" :src="item.teachersAvatar" @click="goDetail(item)" />
          <span>{{item.teachers}}</span>
        </p>
        <p class="p_finaly">
          {{item.sales_num}}人已报名
          <span v-if="item.price == 0">免费</span>
          <span v-else>￥{{item.price}}</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import { NavBar, Icon } from "vant";
import { getLikeList, delLike } from "../../https/https";
export default {
  components: {
    NavBar,
    Icon,
  },
  data() {
    return {
      list: [],
      shoucangNab: null,
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    goDetail(item) {
      console.log(item);
      this.$router.push({
        path: "/detail",
        query: { basis_id: item.course_id },
      });
    },
    delLike() {
      delLike(this.shoucangNab).then((res) => {
        console.log(res);
        getLikeList({
          page: 1,
          limit: 10,
          type: 1,
        }).then((res) => {
          console.log(res);
          this.list = res.list;
        });
      });
    },
  },
  mounted() {
    getLikeList({
      page: 1,
      limit: 10,
      type: 1,
    }).then((res) => {
      console.log(res);
      this.list = res.list;
      this.list.forEach((ele) => {
        this.shoucangNab = ele.collect_id;
      });
    });
  },
};
</script>

<style scoped>
.icon {
  font-size: 20px;
  z-index: 99;
}
.like {
  background-color: #eeeeee;
  padding-bottom: 100px;
}
.jing {
  margin-top: 10px;
  background-color: #f4f4f4;
  overflow: hidden;
}
.jing_for {
  width: 90%;
  height: 180px;
  margin: 0 auto;
  margin-bottom: 10px;
  border-radius: 10px;
  overflow: hidden;
  background-color: #ffffff;
  font-size: 16px;
}
.jing_for > p {
  margin-left: 15px;
  margin-top: 15px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.p_main {
  display: flex;
  align-items: center;
}
.p_small {
  color: #999;
  font-size: 12px;
}
.p_main span {
  color: #999;
  font-size: 12px;
  margin-left: 20px;
}
.jing_img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}
.p_finaly {
  padding-top: 5px;
  padding-right: 10px;
  border-top: 1px solid #999;
  color: #666;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
}
.p_finaly span:nth-child(2) {
  font-size: 16px;
  color: green;
}
</style>